package com.ada.workweixin;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;

import java.util.List;

public class App {

    public static void main(String[] args) throws WxErrorException {

        WxCpDefaultConfigImpl storage = new WxCpDefaultConfigImpl();
        storage.setCorpId("ww864a3bf92f27ecbb");
        storage.setAgentId(1000020);
        storage.setCorpSecret("SlPgVN821c38ZfgUGlXqwE_tySX9kFKfscnwQ7VftHU");
        WxCpService wxCpService = new WxCpServiceImpl();
        wxCpService.setWxCpConfigStorage(storage);
        System.out.println(wxCpService.getAccessToken());
        List<WxCpDepart> departs = wxCpService.getDepartmentService().list(null);
        for (WxCpDepart depart : departs) {
            System.out.println(depart);
        }
        List<WxCpUser> users = wxCpService.getUserService().listByDepartment(departs.get(0).getId(), true, null);
        for (WxCpUser user : users) {
            System.out.println(user);
        }
        WxCpMessage message = WxCpMessage.TEXT().build();
        message.setContent("你好");
        message.setToUser("service");
        wxCpService.getMessageService().send(message);
        WxCpUser user = users.get(0);
        //wxCpService.getUserService().update(user);
        List<String> cs=  wxCpService.getExternalContactService().listFollowers();
        for (String c : cs) {
            System.out.println(c);
        }

    }
}
